menu(){
	echo "有以下操作:1:加法;2:减法;3:乘法;4:除法;5:退出"
	read -p "请输入你的选择：" ans
}

#接受用户输入
input1(){
	while :
	do
		read -p "请输入第一个操作数：" n1 
		#echo $n1 | grep -E "[^0-9]" 
		#a=$(echo $?)
		#if (($a != 0 ));then
		 #      break;
	       #fi
	       if ! echo $n1  |egrep "[^0-9]" &>/dev/null ;then
		       break
	       fi
       done	       
}
input2(){
	while :
	do 
		read -p "请输入第二个操作数：" n2
		echo $n2 |grep -E "[^0-9]"
		b=$(echo $?)
		if (( $b != 0 ));then
			break;
		fi
	done
}
f_sum(){
	input1 	
	input2
	echo "$n1+$n2=$(($n1 + $n2))"
}
f_sub(){
	input1 	
	input2
	echo "$n1-$n2=$(($n1 - $n2))"
}
f_mul(){
	input1 	
	input2
	echo "$n1*$n2=$(($n1 * $n2))"
}

f_div(){
	input1 	
	while :
	do
		input2
		if (($n2!=0));then
			break;
		fi
		echo "除数不能为0"
	done
	echo "$n1/$n2=$(($n1 / $n2))"
}
main(){
	menu
	case $ans in
	1)
		f_sum
		;;
	2)
		f_sub
		;;
	3)
		f_mul
		;;
	4)
		f_div
		;;
	5)
		exit
		;;
	*)
		echo "输入错误，请输入1,2,3,4,5"
		;;
	esac
}
while :
do
	main
done
